package org.dicr.util.protect;

import java.util.prefs.*;

/**
 * <p>
 * Title: Akusher
 * </p>
 * <p>
 * Description: Akusher Database
 * </p>
 * <p>
 * Copyright: Copyright (c) 2003
 * </p>
 * <p>
 * Company: Dicr
 * </p>
 * 
 * @author Igor Tarasov, linux@dicr.org
 * @version 1.0
 */

public class ClockReverse {

	protected static Preferences prefs = Preferences.systemNodeForPackage(ClockReverse.class);

	/**
	 * @throws IllegalStateException
	 */
	public static void checkClock() throws IllegalStateException {
		long lasttime = prefs.getLong("lu", System.currentTimeMillis()); //$NON-NLS-1$
		long curtime = System.currentTimeMillis();
		if (lasttime - 7200 * 1000 > curtime) {
			if (lasttime != Long.MAX_VALUE) {
				prefs.putLong("lu", Long.MAX_VALUE); //$NON-NLS-1$
			}
			throw new IllegalStateException("Ahala mahala !!!"); //$NON-NLS-1$
		}
		prefs.putLong("lu", curtime); //$NON-NLS-1$
	}
}
